Skip to content

Conversation

@kevinsimper
Copy link
Contributor

I was curious how local state was preserved across hibernations, so I tested it with a simple example using Math.random(). Turns out the entire workflow function re-executes from the start after hibernation, only step returns are preserved. It could have been that the state of the isolate was saved.

This isn't immediately obvious from the existing "Do not rely on state outside of a step" section, so I've added a new section that explicitly explains:

  • The workflow function re-executes after hibernation
  • Variables outside steps get new values (especially problematic with Math.random())
  • Loop counters need to be in step returns or they'll reset

I also added a loop example which there is none of in the examples right now 😄

@timfish
Copy link

timfish commented Oct 13, 2025

Great addition. We had to work this out ourselves!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

October 2025 product:workflows Workflows: https://developers.cloudflare.com/workflows/ size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants